<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@page import="java.util.*" %>
<%@page import="com.lmpop.frame.util.FileIO" %>
<%@page import="com.lmpop.frame.util.Config" %>
<%@page import="java.io.*" %>
<%@ page import="java.util.Date"%>
<%@ page import="java.text.SimpleDateFormat"%>
	<%
	request.setCharacterEncoding("UTF-8");
	String cust_id="";
	String file_path = "";
	String file_path_tem = "";
	if( session.getAttribute("session_cust_id") != null )
	{
		cust_id = session.getAttribute("session_cust_id").toString();
	}
	if(request.getParameter("file_path")!=null && !request.getParameter("file_path").equals("/")  ){
		  file_path_tem =  file_path;
		  file_path =  request.getParameter("file_path") ;	
	}	
	Config configFile = new Config();
	String rootpath = configFile.getString("rootpath");
	String tempDir =rootpath+"templets/html/company/web/"+cust_id+"/"+ file_path + "/";
	String LOGODir =rootpath+"templets/html/www/images/logo.jpg";
	%>
<html>		
  <head>
  <title>在线编辑模板</title>
	<link href="/program/admin/index/css/style.css" rel="stylesheet" type="text/css">
	<script type="text/javascript" src="/js/commen.js"></script>
</head>

<body>
	<table width="100%" cellpadding="0" cellspacing="0" border="0">
		<tr>
			<td width="90%">
				<h1>在线编辑模板</h1>					
			</td>
		</tr>
	</table>
<form action="doUpLoad.jsp" name="uploadForm" method="post" enctype="multipart/form-data">
	<table width="100%" cellpadding="0" cellspacing="0" border="0" class="dl_bg" >
  <tr>
     <td class="dl_bg"><h1>LOGO上传</h1></td>
  </tr> 
  <tr>
  <td>
		<p>当前LOGO</p>
		<P><img src="/templets/html/www/images/logo.jpg" width="160" height="160" border="0"/></a></P>
	</td>
    <td align="center">
		<p><input type="file" name="file" id="file" value=""/></p>
		<p><input type="submit" name="Submit" value="提交" class="buttab" /></p>
	</td>
	
    </tr>
 </table>
 </form>

	<form action="submit.jsp" name="indexForm" id="indexForm" method="post" target="_self">
	<table width="100%" cellpadding="1" cellspacing="1" border="0" class="dl_bg">
	 <tr>
    <td><h1>在线编辑模板</h1></td>
  </tr></table>
  <table width="100%" cellpadding="1" cellspacing="1" border="0" class="listtab">
		  <tr>
		   <td > 
		   <%if(!file_path.equals("/")){%>
		   <img width="16" height="16" src="/program/admin/images/dir2.gif"><a href="/program/admin/editTemplets/index.jsp?file_path=<%=file_path_tem%>">上级目录</a>
		   <%}%>
		   </td>
		   <td colspan="3">
			当前目录： <%=file_path%> 
		   </td>
		   </tr>
		   
		<tr>
		  <th width="35%">文件名称</th>
		  <th width="20%">文件大小</th>
		  <th width="35%">编辑时间</th>
		  	
			<th width="10%">编辑</th>

		</tr>	
	<% 
	  File file = new File(tempDir);  
	  String[] filelist   =   file.list(); 
	  if (filelist!=null)
	  {
	  if(filelist.length > 0)
	  {	 
	  	for (int i = 0; i < filelist.length; i++) 
	  	{
				String file_path_mo = file_path + "/"+filelist[i];
				String file_view_path = "/templets/html/www/"+ file_path_mo;
	  		String templateDir =rootpath+"templets/html/www/"+file_path_mo;
	  		File file_o = new File(templateDir); 
	  		Date filedate = new Date();
				filedate.setTime(file_o.lastModified());
				//格式化输出时间
				SimpleDateFormat formate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				String filedateformated = formate.format(filedate);
	  		String filesize=file_o.length() / 1024 +1+ " KB";
				boolean isdirectory = file_o.isDirectory();
				boolean isImage = true;
				String reg="(?i).+?\\.(jpg|gif|jpeg|png|bmp)";
				String file_reg="(?i).+?\\.(html|png|bmp|js|css)";
				isImage = file_view_path.matches(reg);
				String file_ending = "";
				int file_end_num = file_path_mo.lastIndexOf(".");
				int file_length = file_path_mo.length();
				if(file_end_num > 0)
				{
					file_ending = file_path_mo.substring(file_end_num + 1,file_length);
					 
					if(!filelist[i].matches(file_reg))
					{
						file_ending = "other";
					}
				} 
		
				if(isdirectory)
				{
					file_ending = "directory";
				} 
				String filetype="";
				if (filelist[i].equals("footer.html")) filetype = "(网站底部模板)";
				if (filelist[i].equals("toptemp.html")) filetype = "(网站头部模板)";
				if (filelist[i].equals("goods_detail.html")) filetype = "(商品详细页面模板)";
				if (filelist[i].equals("index.html")) filetype = "(网站首页模板)";
				if (filelist[i].equals("normalbiz_detail.html")) filetype = "(商机详细页面模板)";
				if (filelist[i].equals("news_detail.html")) filetype = "(资讯详细页面模板)";
				if (filelist[i].equals("goods_category.html")) filetype = "(全部商品分类页面模板)";
				if (filelist[i].equals("list_supply.jsp")) filetype = "(商机列表页面模板)";
				if (filelist[i].equals("list.jsp")) filetype = "(资讯列表页面模板)";
				if (filelist[i].equals("goods_list.jsp")) filetype = "(商品列表页面模板)";
				
				if (filelist[i].equals("top.html") || filelist[i].equals("Inquiry.jsp") || filelist[i].equals("quote.jsp")) continue;
				
				if (!file_ending.equals("jsp") && !file_ending.equals("html")) continue;
				
				 
		 
				
	%>	

		<tr>  	
		  <td>
		  <%if(isdirectory) {%>
		  <a href="index.jsp?file_path=<%=file_path_mo%>"><img src="/program/admin/images/<%=file_ending%>.gif" /><%=filelist[i]%> </a>
		  <%} else { %>
			<%if(!isImage){%>
			<a href="edit.jsp?filelist=<%=filelist[i]%>&file_path=<%=file_path + "/"%>"><img src="/program/admin/images/<%=file_ending%>.gif" /><%=filelist[i]%><%=filetype%></a>
			<%} else {%>
			<a href="###" onclick="javascript:window.open('<%=file_view_path%>')"><img src="/program/admin/images/<%=file_ending%>.gif" /><%=filelist[i]%></a>
			<%}%>
		  <%}%>
		  	
		  	
		  
		  
		  </td>
		  <td><%=filesize%></td>
		  <td><%=filedateformated%></td>	
		  <td width="10%">
		  <%if(isdirectory) {%>
		  <a href="index.jsp?file_path=<%=file_path_mo%>"><img src="/program/admin/images/img_view.png" title="查看文件夹" /></a>
		  <%} else { %>
			<%if(!isImage){%>
			<a href="edit.jsp?filelist=<%=filelist[i]%>&file_path=<%=file_path + "/"%>"><img src="/program/admin/images/edit.gif" title="编辑" /></a>
			<%} else {%>
			<a href="###" onclick="javascript:window.open('<%=file_view_path%>')"><img src="/program/admin/images/zoom.png" title="查看" /></a>
			<%}%>
		  <%}%>
		  </td>

		</tr>		
	<% 
  	}	
  }	
  }
	%>				

</table>

</form>
</body>

</html>
